package com.cloudlinkscm.base.authcenter.controller;

import com.cloudlinkscm.base.authcenter.model.PublicResource;
import com.cloudlinkscm.base.authcenter.model.dto.PublicResourceSaveDTO;
import com.cloudlinkscm.base.authcenter.model.dto.PublicResourceUpdateDTO;
import com.cloudlinkscm.base.authcenter.model.dto.ResourceTree;
import com.cloudlinkscm.base.authcenter.service.PublicResourceService;
import com.cloudlinkscm.loms.framework.core.pojo.RestfulApiResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by sin on 2017/8/7.
 *
 * 公共：权限资源
 */
@RestController
public class PublicResourceController {


	@Autowired
	private PublicResourceService publicResourceService;

	@ApiOperation("公共资源：保存")
	@RequestMapping(value = "public_resource/save", method = RequestMethod.POST)
	public RestfulApiResponse<PublicResource> save(@RequestBody PublicResourceSaveDTO saveDTO) {
		return RestfulApiResponse.success(publicResourceService.save(saveDTO));
	}

	@ApiOperation("公共资源：更新")
	@RequestMapping(value = "public_resource/update", method = RequestMethod.PUT)
	public RestfulApiResponse<PublicResource> update(@RequestBody PublicResourceUpdateDTO updateDTO) {
		return RestfulApiResponse.success(publicResourceService.update(updateDTO));
	}

	@ApiOperation("公共资源：删除")
	@RequestMapping(value = "public_resource/{id}/remove", method = RequestMethod.DELETE)
	public RestfulApiResponse remove(@PathVariable("id") String id) {
		return RestfulApiResponse.success("删除成功", publicResourceService.remove(id));
	}

	@ApiOperation("公共资源：Tree")
	@RequestMapping(value = "public_resource/tree", method = RequestMethod.GET)
	public RestfulApiResponse<List<ResourceTree>> tree() {
		return RestfulApiResponse.success(publicResourceService.tree());
	}
}
